using AnhAnh;
using AutoSales;
using Facebook;
using FacebookLib;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Resources;
using System.Threading;
using System.Windows.Forms;

public sealed class FormGroupSearch : Form
{
	private BindingSource bindingSource_0 = new BindingSource();

	private List<GroupData> list_0;

	private FacebookClient facebookClient_0;

	private bool bool_0;

	private IContainer icontainer_0;

	private DataGridView dataGridView1;

	private Button buttonSearch;

	private TextBox textBoxValue;

	private Button buttonJoin;

	private TextBox textBoxMin;

	private Label label1;

	private Label label2;

	private WebBrowser web;

	private ComboBox comboBoxLanguage;

	private Label label3;

	private Button buttonClearAll;

	private StatusStrip statusStrip1;

	private ToolStripStatusLabel toolStripStatusLabel1;

	private ToolStripProgressBar toolStripProgressBar1;

	private ToolStripStatusLabel toolStripStatusLabel2;

	private CheckBox checkBoxSelectAll;

	private CheckBox checkBoxExactly;

	public FormGroupSearch()
	{
		this.InitializeComponent();
	}

	private void buttonClearAll_Click(object sender, EventArgs e)
	{
		if (this.dataGridView1.Rows.Count == 0)
		{
			return;
		}
		if (UI.ConfirmDelete())
		{
			this.bindingSource_0.Clear();
		}
	}

	private void buttonJoin_Click(object sender, EventArgs e)
	{
		if (this.dataGridView1.Rows.Count == 0)
		{
			return;
		}
		this.buttonJoin.Text = (this.buttonJoin.Text == "Join" ? "Stop" : "Join");
		if (this.buttonJoin.Text != "Stop")
		{
			return;
		}
		this.method_0("Joining ..", true, string.Empty, true);
		try
		{
			int num = 0;
			foreach (DataGridViewRow row in (IEnumerable)this.dataGridView1.Rows)
			{
				Application.DoEvents();
				if (this.buttonJoin.Text != "Stop")
				{
					break;
				}
				if (!(bool)row.Cells["select"].Value || (bool)row.Cells["sent"].Value)
				{
					continue;
				}
				this.bool_0 = false;
				this.web.Navigate(string.Concat("https://m.facebook.com/groups/", row.Cells["id"].Value));
				Anh.WaitingForBrowser(this.web);
				if (num == 0 && !row.Displayed)
				{
					this.dataGridView1.FirstDisplayedScrollingRowIndex = row.Index;
				}
				row.Cells["sent"].Value = true;
				num++;
				row.DefaultCellStyle.BackColor = Color.LightPink;
				this.method_6(num);
			}
		}
		catch (Exception exception)
		{
			UI.ShowMessage(exception, false);
		}
		this.buttonJoin.Text = "Join";
		this.method_0("Joining completed", false, string.Empty, false);
		Anh.ReleaseMemory();
	}

	private void buttonSearch_Click(object sender, EventArgs e)
	{
		if (string.IsNullOrEmpty(this.textBoxValue.Text))
		{
			UI.ShowMessage("Please enter a name value", "Invalid entry", UI.MessageType.Error);
			this.textBoxValue.Focus();
			return;
		}
		int num = 0;
		if (!string.IsNullOrEmpty(this.textBoxMin.Text) && !int.TryParse(this.textBoxMin.Text.Trim(), out num))
		{
			UI.ShowMessage("Please enter correct value for members", "Invalid entry", UI.MessageType.Error);
			this.textBoxMin.Focus();
			return;
		}
		this.buttonSearch.Text = (this.buttonSearch.Text == "Search" ? "Stop" : "Search");
		if (this.buttonSearch.Text != "Stop")
		{
			return;
		}
		this.method_0("Searching ..", true, string.Empty, true);
		int num1 = 0;
		List<GroupData> groupDatas = FormMain.mCoca.SearchGroup(this.facebookClient_0, this.textBoxValue.Text.Trim());
		if (this.list_0 == null)
		{
			this.list_0 = FormMain.mCoca.GetMyGroups(this.facebookClient_0);
		}
		List<GroupData> list = groupDatas.Except<GroupData>(this.list_0, new GroupDataComparer()).ToList<GroupData>();
		foreach (GroupData groupDatum in list)
		{
			Application.DoEvents();
			if (this.buttonSearch.Text != "Stop")
			{
				break;
			}
			if (this.checkBoxExactly.Checked && !groupDatum.name.ToLower().Contains(this.textBoxValue.Text.Trim().ToLower()))
			{
				continue;
			}
			if (this.comboBoxLanguage.SelectedIndex == 1)
			{
				if (!this.method_5(groupDatum))
				{
					continue;
				}
			}
			else if (this.comboBoxLanguage.SelectedIndex == 2 && !this.method_4(groupDatum))
			{
				continue;
			}
			if (this.method_3(groupDatum.id))
			{
				continue;
			}
			if (groupDatum.privacy != "CLOSED")
			{
				groupDatum.members = FormMain.mCoca.CountGroupMembers(this.facebookClient_0, groupDatum.id);
			}
			else
			{
				groupDatum.members = 0;
			}
			if (groupDatum.members != 0 && groupDatum.members < num)
			{
				continue;
			}
			this.bindingSource_0.Add(groupDatum);
			this.bindingSource_0.MoveLast();
			num1++;
		}
		this.buttonSearch.Text = "Search";
		this.method_0(string.Format("Search completed, {0} group found", num1), false, string.Empty, false);
	}

	private void checkBoxSelectAll_CheckedChanged(object sender, EventArgs e)
	{
		foreach (DataGridViewRow row in (IEnumerable)this.dataGridView1.Rows)
		{
			row.Cells["select"].Value = this.checkBoxSelectAll.Checked;
		}
	}

	private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
	{
		if (e.RowIndex < 0)
		{
			return;
		}
		if (e.ColumnIndex == this.dataGridView1.Columns["link"].Index && this.dataGridView1.Rows[e.RowIndex].Cells["link"] != null)
		{
			Process.Start(this.dataGridView1.Rows[e.RowIndex].Cells["link"].Value.ToString());
		}
	}

	private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
	{
		DataGridViewRow item = this.dataGridView1.Rows[e.RowIndex];
		int rowIndex = e.RowIndex + 1;
		item.HeaderCell.Value = rowIndex.ToString();
		DataGridViewLinkCell dataGridViewLinkCell = new DataGridViewLinkCell()
		{
			Value = string.Concat("https://www.facebook.com/", item.Cells["id"].Value)
		};
		item.Cells["link"] = dataGridViewLinkCell;
		item.Cells["select"].Value = true;
		item.Cells["sent"].Value = false;
		this.dataGridView1.Columns["id"].Visible = false;
		this.dataGridView1.Columns["name"].Width = 220;
	}

	protected override void Dispose(bool bool_1)
	{
		if (bool_1 && this.icontainer_0 != null)
		{
			this.icontainer_0.Dispose();
		}
		base.Dispose(bool_1);
	}

	private void FormGroupSearch_Shown(object sender, EventArgs e)
	{
		this.dataGridView1.DataSource = this.bindingSource_0;
		this.method_2();
		this.facebookClient_0 = new FacebookClient(FormMain.mToken);
		this.comboBoxLanguage.SelectedIndex = 0;
	}

	private void InitializeComponent()
	{
		DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
		ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(FormGroupSearch));
		this.dataGridView1 = new DataGridView();
		this.buttonSearch = new Button();
		this.textBoxValue = new TextBox();
		this.buttonJoin = new Button();
		this.textBoxMin = new TextBox();
		this.label1 = new Label();
		this.label2 = new Label();
		this.web = new WebBrowser();
		this.comboBoxLanguage = new ComboBox();
		this.label3 = new Label();
		this.buttonClearAll = new Button();
		this.statusStrip1 = new StatusStrip();
		this.toolStripStatusLabel1 = new ToolStripStatusLabel();
		this.toolStripProgressBar1 = new ToolStripProgressBar();
		this.toolStripStatusLabel2 = new ToolStripStatusLabel();
		this.checkBoxSelectAll = new CheckBox();
		this.checkBoxExactly = new CheckBox();
		((ISupportInitialize)this.dataGridView1).BeginInit();
		this.statusStrip1.SuspendLayout();
		base.SuspendLayout();
		this.dataGridView1.AllowUserToAddRows = false;
		this.dataGridView1.AllowUserToDeleteRows = false;
		this.dataGridView1.AllowUserToResizeRows = false;
		this.dataGridView1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
		this.dataGridView1.BackgroundColor = SystemColors.Menu;
		this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
		this.dataGridView1.ColumnHeadersHeight = 30;
		this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
		dataGridViewCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle.BackColor = Color.Bisque;
		dataGridViewCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
		dataGridViewCellStyle.ForeColor = SystemColors.ControlText;
		dataGridViewCellStyle.SelectionBackColor = SystemColors.Highlight;
		dataGridViewCellStyle.SelectionForeColor = SystemColors.HighlightText;
		dataGridViewCellStyle.WrapMode = DataGridViewTriState.False;
		this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle;
		this.dataGridView1.Location = new Point(0, 40);
		this.dataGridView1.Name = "dataGridView1";
		this.dataGridView1.RowHeadersWidth = 60;
		this.dataGridView1.RowTemplate.Height = 35;
		this.dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
		this.dataGridView1.Size = new System.Drawing.Size(1000, 399);
		this.dataGridView1.TabIndex = 8;
		this.dataGridView1.CellClick += new DataGridViewCellEventHandler(this.dataGridView1_CellClick);
		this.dataGridView1.RowsAdded += new DataGridViewRowsAddedEventHandler(this.dataGridView1_RowsAdded);
		this.buttonSearch.Location = new Point(570, 9);
		this.buttonSearch.Name = "buttonSearch";
		this.buttonSearch.Size = new System.Drawing.Size(75, 25);
		this.buttonSearch.TabIndex = 4;
		this.buttonSearch.Text = "Search";
		this.buttonSearch.UseVisualStyleBackColor = true;
		this.buttonSearch.Click += new EventHandler(this.buttonSearch_Click);
		this.textBoxValue.Location = new Point(50, 12);
		this.textBoxValue.Name = "textBoxValue";
		this.textBoxValue.Size = new System.Drawing.Size(125, 20);
		this.textBoxValue.TabIndex = 0;
		this.buttonJoin.Anchor = AnchorStyles.Top | AnchorStyles.Right;
		this.buttonJoin.Location = new Point(906, 9);
		this.buttonJoin.Name = "buttonJoin";
		this.buttonJoin.Size = new System.Drawing.Size(75, 25);
		this.buttonJoin.TabIndex = 7;
		this.buttonJoin.Text = "Join";
		this.buttonJoin.UseVisualStyleBackColor = true;
		this.buttonJoin.Click += new EventHandler(this.buttonJoin_Click);
		this.textBoxMin.Location = new Point(348, 12);
		this.textBoxMin.Name = "textBoxMin";
		this.textBoxMin.Size = new System.Drawing.Size(59, 20);
		this.textBoxMin.TabIndex = 2;
		this.label1.AutoSize = true;
		this.label1.Location = new Point(12, 14);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(35, 13);
		this.label1.TabIndex = 23;
		this.label1.Text = "Name";
		this.label2.AutoSize = true;
		this.label2.Location = new Point(280, 14);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(65, 13);
		this.label2.TabIndex = 24;
		this.label2.Text = "Members >=";
		this.web.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
		this.web.Location = new Point(7, 290);
		this.web.MinimumSize = new System.Drawing.Size(20, 20);
		this.web.Name = "web";
		this.web.ScriptErrorsSuppressed = true;
		this.web.Size = new System.Drawing.Size(987, 139);
		this.web.TabIndex = 25;
		this.web.Visible = false;
		this.web.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(this.web_DocumentCompleted);
		this.comboBoxLanguage.FormattingEnabled = true;
		this.comboBoxLanguage.Items.AddRange(new object[] { "[All]", "English", "Vietnamese" });
		this.comboBoxLanguage.Location = new Point(478, 12);
		this.comboBoxLanguage.Name = "comboBoxLanguage";
		this.comboBoxLanguage.Size = new System.Drawing.Size(81, 21);
		this.comboBoxLanguage.TabIndex = 3;
		this.label3.AutoSize = true;
		this.label3.Location = new Point(420, 14);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(55, 13);
		this.label3.TabIndex = 27;
		this.label3.Text = "Language";
		this.buttonClearAll.Anchor = AnchorStyles.Top | AnchorStyles.Right;
		this.buttonClearAll.Location = new Point(815, 9);
		this.buttonClearAll.Name = "buttonClearAll";
		this.buttonClearAll.Size = new System.Drawing.Size(75, 25);
		this.buttonClearAll.TabIndex = 6;
		this.buttonClearAll.Text = "Clear All";
		this.buttonClearAll.UseVisualStyleBackColor = true;
		this.buttonClearAll.Click += new EventHandler(this.buttonClearAll_Click);
		ToolStripItemCollection items = this.statusStrip1.Items;
		ToolStripItem[] toolStripItemArray = new ToolStripItem[] { this.toolStripStatusLabel1, this.toolStripProgressBar1, this.toolStripStatusLabel2 };
		items.AddRange(toolStripItemArray);
		this.statusStrip1.Location = new Point(0, 440);
		this.statusStrip1.Name = "statusStrip1";
		this.statusStrip1.Size = new System.Drawing.Size(999, 22);
		this.statusStrip1.TabIndex = 28;
		this.statusStrip1.Text = "statusStrip123";
		this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
		this.toolStripStatusLabel1.Size = new System.Drawing.Size(0, 17);
		this.toolStripStatusLabel1.TextAlign = ContentAlignment.MiddleLeft;
		this.toolStripProgressBar1.Name = "toolStripProgressBar1";
		this.toolStripProgressBar1.Size = new System.Drawing.Size(150, 16);
		this.toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
		this.toolStripProgressBar1.Visible = false;
		this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
		this.toolStripStatusLabel2.Size = new System.Drawing.Size(0, 17);
		this.checkBoxSelectAll.AutoSize = true;
		this.checkBoxSelectAll.Checked = true;
		this.checkBoxSelectAll.CheckState = CheckState.Checked;
		this.checkBoxSelectAll.Location = new Point(668, 14);
		this.checkBoxSelectAll.Name = "checkBoxSelectAll";
		this.checkBoxSelectAll.Size = new System.Drawing.Size(70, 17);
		this.checkBoxSelectAll.TabIndex = 5;
		this.checkBoxSelectAll.Text = "Select All";
		this.checkBoxSelectAll.UseVisualStyleBackColor = true;
		this.checkBoxSelectAll.CheckedChanged += new EventHandler(this.checkBoxSelectAll_CheckedChanged);
		this.checkBoxExactly.AutoSize = true;
		this.checkBoxExactly.Location = new Point(188, 13);
		this.checkBoxExactly.Name = "checkBoxExactly";
		this.checkBoxExactly.Size = new System.Drawing.Size(82, 17);
		this.checkBoxExactly.TabIndex = 1;
		this.checkBoxExactly.Text = "Find exactly";
		this.checkBoxExactly.UseVisualStyleBackColor = true;
		base.AcceptButton = this.buttonSearch;
		base.AutoScaleDimensions = new SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(999, 462);
		base.Controls.Add(this.checkBoxExactly);
		base.Controls.Add(this.checkBoxSelectAll);
		base.Controls.Add(this.statusStrip1);
		base.Controls.Add(this.buttonClearAll);
		base.Controls.Add(this.label3);
		base.Controls.Add(this.comboBoxLanguage);
		base.Controls.Add(this.web);
		base.Controls.Add(this.label2);
		base.Controls.Add(this.label1);
		base.Controls.Add(this.textBoxMin);
		base.Controls.Add(this.buttonSearch);
		base.Controls.Add(this.textBoxValue);
		base.Controls.Add(this.buttonJoin);
		base.Controls.Add(this.dataGridView1);
		base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
		base.Name = "FormGroupSearch";
		base.StartPosition = FormStartPosition.CenterParent;
		this.Text = "Group Search";
		base.Shown += new EventHandler(this.FormGroupSearch_Shown);
		((ISupportInitialize)this.dataGridView1).EndInit();
		this.statusStrip1.ResumeLayout(false);
		this.statusStrip1.PerformLayout();
		base.ResumeLayout(false);
		base.PerformLayout();
	}

	private void method_0(string string_0, bool bool_1, string string_1, bool bool_2)
	{
		this.method_1(string_0, bool_1, string_1, bool_2, 0, 0);
	}

	private void method_1(string string_0, bool bool_1, string string_1, bool bool_2, int int_0, int int_1)
	{
		Application.DoEvents();
		if (!bool_2)
		{
			this.Cursor = Cursors.Default;
			Application.DoEvents();
		}
		else
		{
			this.Cursor = Cursors.WaitCursor;
			Application.DoEvents();
		}
		if (int_0 != 0 || int_1 != 0)
		{
			ToolStripStatusLabel toolStripStatusLabel = this.toolStripStatusLabel1;
			string[] str = new string[] { "(", int_0.ToString(), "/", int_1.ToString(), ") ", string_0 };
			toolStripStatusLabel.Text = string.Concat(str);
		}
		else
		{
			this.toolStripStatusLabel1.Text = string_0;
		}
		this.toolStripProgressBar1.Visible = bool_1;
		if (string_1 != string.Empty)
		{
			ToolStripStatusLabel toolStripStatusLabel1 = this.toolStripStatusLabel2;
			toolStripStatusLabel1.Text = string.Concat(toolStripStatusLabel1.Text, " | ", string_1);
		}
		Application.DoEvents();
	}

	private void method_2()
	{
		Application.DoEvents();
		if (!this.dataGridView1.Columns.Contains("link"))
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn()
			{
				DisplayIndex = 8,
				Name = "link",
				HeaderText = "link",
				Width = 50
			};
			dataGridViewTextBoxColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
			this.dataGridView1.Columns.Add(dataGridViewTextBoxColumn);
		}
		if (!this.dataGridView1.Columns.Contains("select"))
		{
			DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn = new DataGridViewCheckBoxColumn()
			{
				DisplayIndex = 9,
				Name = "select",
				HeaderText = "select",
				Width = 50
			};
			this.dataGridView1.Columns.Add(dataGridViewCheckBoxColumn);
		}
		if (!this.dataGridView1.Columns.Contains("sent"))
		{
			DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn1 = new DataGridViewCheckBoxColumn()
			{
				DisplayIndex = 10,
				Name = "sent",
				HeaderText = "sent",
				Width = 50,
				Visible = false
			};
			this.dataGridView1.Columns.Add(dataGridViewCheckBoxColumn1);
		}
	}

	private bool method_3(string string_0)
	{
		bool flag;
		IEnumerator enumerator = ((IEnumerable)this.dataGridView1.Rows).GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				DataGridViewRow current = (DataGridViewRow)enumerator.Current;
				if (current.Cells["id"].Value.ToString() != string_0)
				{
					continue;
				}
				flag = true;
				return flag;
			}
			return false;
		}
		finally
		{
			IDisposable disposable = enumerator as IDisposable;
			if (disposable != null)
			{
				disposable.Dispose();
			}
		}
		return flag;
	}

	private bool method_4(GroupData groupData_0)
	{
		if (!FormMain.mAnh.CheckIsVietnamese(groupData_0.name) && !FormMain.mAnh.CheckIsVietnamese(groupData_0.description) && !FormMain.mAnh.CheckIsVietnamese(groupData_0.owner))
		{
			return false;
		}
		return true;
	}

	private bool method_5(GroupData groupData_0)
	{
		if (FormMain.mAnh.CheckIsEnglish(groupData_0.name) && FormMain.mAnh.CheckIsEnglish(groupData_0.description))
		{
			return true;
		}
		return false;
	}

	private void method_6(int int_0)
	{
		Application.DoEvents();
		if (int_0 == 0)
		{
			return;
		}
		if (int_0 % 30 == 0)
		{
			this.web.Navigate(string.Empty);
			Application.DoEvents();
			Thread.Sleep(300);
			Anh.ReleaseMemory();
			for (int i = 0; i < 10; i++)
			{
				if (this.buttonJoin.Text == "Join")
				{
					return;
				}
				Application.DoEvents();
				Thread.Sleep(300);
			}
		}
	}

	private void web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
	{
		Application.DoEvents();
		Thread.Sleep(2000);
		if (this.bool_0)
		{
			return;
		}
		HtmlElement htmlElement = null;
		bool flag = FormMain.mLocale.StartsWith("en_");
		bool flag1 = FormMain.mLocale.StartsWith("vi_");
		if (flag)
		{
			htmlElement = FormMain.mAnh.GetHtmlElement(this.web.Document, "groupJoinHeaderButton");
		}
		else if (flag1)
		{
			htmlElement = FormMain.mAnh.GetHtmlElement(this.web.Document, "groupJoinHeaderButton");
		}
		if (htmlElement != null)
		{
			this.bool_0 = FormMain.mAnh.SetHtmlElement(htmlElement);
		}
	}
}